<?php
namespace app\common\controller;
use think\Request;

class Files
{
	const STATUS_CODE_ONE = 10001;
	const STATUS_CODE_TWO = 10002;
	const STATUS_CODE_THREE = 10003;
	/**
	* 文件上传
	*/
	public static function upload($path,$name)
	{
		$file = request()->file($name);
		if(!$file)
		{
			return ['code'=>self::STATUS_CODE_TWO,'msg'=>'文件不存在'];
		}
		if($file){
			$info = $file->move($path);
			if($info){
				return ['code'=>self::STATUS_CODE_ONE,'msg'=>$path . DS . $info->getSaveName()];
			}else{
				return ['code'=>self::STATUS_CODE_THREE,'msg'=>$file->getError()];
			}
		}
	}
	/**
	* 文件下载
	*/
	public static function download($path,$filename)
	{
		/*告诉浏览器通过附件形式来处理文件*/
		header( "Content-Disposition:  attachment;  filename=".$filename); 
		/*下载文件大小*/
		header('Content-Length: ' . filesize($path));
		/*读取文件内容*/		
		readfile($path);
	}
	
}
